<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta charset="UTF-8">
		<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/css/base.css">
		<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/css/style.css">
		<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-2.1.4.min.js"></script>
		<title>订单管理-需求池</title>
	</head>
	<body>
		<div class="page">
			<div class="header">
				<div class="header_top"></div>
				<div class="header_bottom clearfix">
					<div class="header_logo fl">
						<img src="${pageContext.request.contextPath}/images/images/index-logo.png">
					</div>
					<ul class="header_nav clearfix fl">
						<li>
							<a href="${pageContext.request.contextPath}/morder/waitOrderList.html" class="on">订单管理</a>
						</li>
						<li>
							<a href="${pageContext.request.contextPath}/staff/queryAllList/1.html">家政人员管理</a>
						</li>
						<li>
							<a href="${pageContext.request.contextPath}/supplier/account.html">财务管理</a>
						</li>
						<li>
							<a href="${pageContext.request.contextPath}/admin/accountInfo.html" >账户管理</a>
						</li>
					</ul>
					<div class="header_user fr">
						<img src="${pageContext.request.contextPath}/images/images/user.png">欢迎您，<i>${ sessionScope.MANAGER_NAME} </i><a href="${pageContext.request.contextPath}/manager/loginout.html">【切换账号】</a>
					</div>
				</div>
			</div>
			<div class="main clearfix">
				<div class="main_menu fl">
				
				
					<div class="menu_name">
						<a href="${pageContext.request.contextPath}/morder/waitOrderList.html">
							<img src="${pageContext.request.contextPath}/images/images/ddc.png">
							<p>订单池</p>
						</a>
					</div>
					<div class="menu_name on">
						<a href="${pageContext.request.contextPath}/need/waitNeedList/1.html">
							<img src="${pageContext.request.contextPath}/images/images/xqc.png">
							<p>需求池</p>
						</a>
					</div>
					<div class="menu_name">
						<a href="${pageContext.request.contextPath}/morder/allOrderList/3/1.html">
							<img src="${pageContext.request.contextPath}/images/images/wddd.png">
							<p>我的订单</p>
						</a>
					</div>
					
				</div>
				<div class="main_cont fl">
					<div class="main_cont_top">
						<div class="main_inner clearfix">
							<div class="cont_top_title fl">当前位置：订单管理 > 需求池</div>
							<div class="cont_top_time fr"> <i><img src="${pageContext.request.contextPath}/images/images/refresh.png">
							<a href="${pageContext.request.contextPath}/need/waitNeedList/1.html">刷新</a>
							</i></div>
						</div>
					</div>
					<div class="main_cont_top">
						<div class="main_inner clearfix">
							<div class="cont_top_title fl">我的嘿币：<i>${suMoney}</i> 元</div>
							<div class="cont_top_time fr">
								<!-- <select>  
									<option value ="全部订单">全部订单</option>
								</select> -->
								<form action="${pageContext.request.contextPath}/need/waitNeedList/1.html" id="youform">
								下单时间：<input class="Wdate" type="text" onClick="WdatePicker()" name="starts">  到  
								<input class="Wdate" type="text" onClick="WdatePicker()" name="ends">
								<input type="submit" value="订单搜索" class="search" >
								</form>
							</div>
						</div>
					</div>
					<div class="main_cont_bottom_xqc">
						<div class="main_inner">
							<table>
							    <thead>
							    <tr> 
							        <th>需求编号</th> 
							        <th>需求工种</th>
							        <th>需求价格</th> 
							        <th>服务地址</th>
							        <th>需求提交时间</th> 
							        <th>用户备注</th>
							        <th>操作</th>
							    </tr>
							    </thead>  
							    <tbody>
							    <c:forEach items="${PAGE_BEAN.dataList}" var="need">
									<tr class="text-c">
										<td><c:out value="${need.id}"/></td>
										<td> 
										<c:if test="${need.wNeedType eq 9}">
											月嫂
										</c:if>
										<c:if test="${need.wNeedType eq 7}">
											医院护工
										</c:if>
										<c:if test="${need.wNeedType eq 8}">
											育婴师
										</c:if>
										<c:if test="${need.wNeedType eq 6}">
											保姆
										</c:if>
										<c:if test="${need.wNeedType eq 10}">
											看护老人
										</c:if>
									</td>
										<td><c:out value="${need.wFeeType}"/></td>
										<td><c:out value="${need.wAddress}"/></td>
										<td><fmt:formatDate value="${need.createTime}" type="BOTH" dateStyle="full"/></td>
										<td><c:out value="${need.wDesc}"/></td>
										<td class="td-manage">
											<button  onclick="preNeed(${need.id},'${need.wFeeType}');">支付抢单</button>						
										</td>
									</tr>
								</c:forEach>
								</tbody> 
							</table>
							<%@ include file="/WEB-INF/views/page.jsp"%>
							<input type="hidden" id="sMoney" value="${suMoney}"/>
						</div>
					</div>
				</div>
			</div>
			<!--抢单成功-->
			<div class="mask">
				<div class="qiangdan">
					<img src="${pageContext.request.contextPath}/images/images/close.png" class="close" onclick="closeD()">
					<h3>抢单成功！</h3>
					<p>请前往我的订单——><a href="${pageContext.request.contextPath}/need/waitNeedList/1.html?flag=1">我的需求</a>查看详情</p>
				</div>
			</div>
			<!--有余额时-->
			<div class="mask_yyue">
				<div class="yyue">
					<img src="${pageContext.request.contextPath}/images/images/close.png" class="close" onclick="closeD()">
					<p class="mt30">此单需支付的嘿币为：<i id="nmoney"></i>元</p>
					<p>您的嘿币余额为：<i id="ecu"></i>元</p>
					<p>是否支付并抢单？</p>
					<div class="btn">
						<input type="hidden" id="needId"/>
						<input type="hidden" id="heibi"/>
						<button class="qx" onclick="closeD()">取消</button><button class="zfqd" onclick="rushNeed()">支付抢单</button>
					</div>
				</div>
			</div>
			<!--余额不足-->
			<div class="mask_yuebz">
				<div class="yyue">
					<img src="${pageContext.request.contextPath}/images/images/close.png" class="close" onclick="closeD()">
					<p class="mt30">此单需支付的嘿币为：<i id="nmoney1"></i>元</p>
					<p>您的嘿币余额为：<i id="ncu"></i>元</p>
					<p>抱歉，您的余额不足，无法抢单！</p>
					<div class="btn">
						<button class="qx" onclick="closeD()">取消</button><button class="zfqd">去充值</button>
					</div>
				</div>
			</div>
		</div>
		
		<script type="text/javascript" src="${pageContext.request.contextPath}/lib/layer/2.1/layer.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/lib/laypage/1.2/laypage.js"></script> 
		<script type="text/javascript" src="${pageContext.request.contextPath}/lib/My97DatePicker/WdatePicker.js"></script> 
		<script type="text/javascript" src="${pageContext.request.contextPath}/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
				<script type="text/javascript">
				$(function(){
					$('.table-sort').dataTable({
						"bLengthChange": false, //改变每页显示数据数量
						"aaSorting": [[ 1, "desc" ]],//默认第几个排序
						"bStateSave": true,//状态保存
						"bPaginate" : false,// 分页按钮  
						"aoColumnDefs": [
						  //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
						  {"orderable":false,"aTargets":[0,3,3]}// 制定列不参与排序
						]
					});								
				});
				
				
		
				function closeD(){
						$(".mask").hide();
						$(".mask_yyue").hide();
						$(".mask_yuebz").hide();
					}
					
				function preNeed(nid,fees){
						var strs=fees.split("-");
						var tempts=0;
						if(strs.length>1){
						    tempts=strs[1];
						}else{
							tempts=fees;
						}
						
						//嘿币兑换的计算方式是 20%*20%
						var nums=parseInt(parseInt(tempts)*0.04);
						var suppMoney=$('#sMoney').val(); 
						
						if(parseInt(suppMoney)>=nums){
							var total=parseInt(suppMoney-nums);
							$('#ecu').html(total);
							$('#nmoney').html(nums);
							$('#heibi').val(nums);
							$('#needId').val(nid);
							$(".mask_yyue").show(); 
						}else{
							$('#ncu').html(suppMoney);
							$('#nmoney1').html(nums);
							$(".mask_yuebz").show(); 
						}   
					}	
				
				function rushNeed(){
					var needId=$('#needId').val();
					var heibi=$('#heibi').val();
						$.ajax({
							  type:"get",
							  url: "${pageContext.request.contextPath}/need/confirmNeed/"+needId+".json?heibi="+heibi,
							  success:function(data) {
								  alert(data.info);
								  var flags=data.status;
								  if(flags!=null && flags!="0"){
									  quexiao();
								  }else{
									  closeD();
								  }
								 
							  }
						});  
					}	
				
				function quexiao(){
					$(".mask_yyue").hide();
					$(".mask").show();
					}
				
					
				</script>
	</body>
</html>
